package org.game.db.bean;

import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import org.apache.commons.lang3.ArrayUtils;
import com.sojoys.artifact.build.data.base.BasePojo;
import static org.game.db.StaticResource.DatingResource.*;
import java.util.List;
import java.sql.SQLException;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import org.game.db.cache.PlayerCache;
import java.sql.ResultSet;
import java.util.Map;
import org.game.db.cache.DatingCache;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static org.game.db.StaticResource.DatingResource.*;
/**
 * 玩家约会记录
 */
public class Dating extends BasePojo<Dating> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[2];
	
	/**
	* id
	*/
	private long id;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	/**
	* 玩家id
	*/
	private int playerId;
	
	/**
	* 对话选择次数记录
	*/
	private Map dialogueCount;
	
	/**
	* 剧本id记录列表
	*/
	private List scriptIdList;
	
	/**
	* 结束节点列表（用于前台显示攻略记录）
	*/
	private List endNodeList;
	
	/**
	* 上次触发预定约会时间
	*/
	private java.util.Date lastTriggerReverseDatingTime;
	
	/**
	* 上次预定约会次数刷新时间
	*/
	private java.util.Date lastReserveDatingRefreshTime;
	
	
	@Deprecated
	public static Dating builder() {
		Dating dating = new Dating();
		return dating;
	}
	
	@Deprecated
	public Dating() {
		super();
	}
	
	public Dating(long id, int playerId, Map dialogueCount, List scriptIdList, List endNodeList, java.util.Date lastTriggerReverseDatingTime, java.util.Date lastReserveDatingRefreshTime) {
		super();
		this.id = id;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
		this.playerId = playerId;
		this.dialogueCount = dialogueCount;
		this.scriptIdList = scriptIdList;
		this.endNodeList = endNodeList;
		this.lastTriggerReverseDatingTime = lastTriggerReverseDatingTime;
		this.lastReserveDatingRefreshTime = lastReserveDatingRefreshTime;
	}
	
	/**
	 * id
	 */
	public long getId() {return id;}
	
	/**
	 * id
	 */
	public Dating setId(long id) {this.id = id;return this;}
	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected Dating setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected Dating setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	/**
	 * 玩家id
	 */
	public int getPlayerId() {return playerId;}
	
	/**
	 * 玩家id
	 */
	public Dating setPlayerId(int playerId) {this.playerId = playerId;return this;}
	
	/**
	 * 对话选择次数记录
	 */
	public Map getDialogueCount() {return dialogueCount;}
	
	/**
	 * 对话选择次数记录
	 */
	public Dating setDialogueCount(Map dialogueCount) {this.dialogueCount = dialogueCount;return this;}
	
	/**
	 * 对话选择次数记录
	 */
	public byte[] getDialogueCountByte() {
		return toBytes(dialogueCount);
	}
	
	/**
	 * 对话选择次数记录
	 */
	public Map initDialogueCountByte(byte[] _byte) {
		return (Map)forBytesObject(_byte);
	}	
	/**
	 * 剧本id记录列表
	 */
	public List getScriptIdList() {return scriptIdList;}
	
	/**
	 * 剧本id记录列表
	 */
	public Dating setScriptIdList(List scriptIdList) {this.scriptIdList = scriptIdList;return this;}
	
	/**
	 * 剧本id记录列表
	 */
	public byte[] getScriptIdListByte() {
		return toBytes(scriptIdList);
	}
	
	/**
	 * 剧本id记录列表
	 */
	public List initScriptIdListByte(byte[] _byte) {
		return (List)forBytesObject(_byte);
	}	
	/**
	 * 结束节点列表（用于前台显示攻略记录）
	 */
	public List getEndNodeList() {return endNodeList;}
	
	/**
	 * 结束节点列表（用于前台显示攻略记录）
	 */
	public Dating setEndNodeList(List endNodeList) {this.endNodeList = endNodeList;return this;}
	
	/**
	 * 结束节点列表（用于前台显示攻略记录）
	 */
	public byte[] getEndNodeListByte() {
		return toBytes(endNodeList);
	}
	
	/**
	 * 结束节点列表（用于前台显示攻略记录）
	 */
	public List initEndNodeListByte(byte[] _byte) {
		return (List)forBytesObject(_byte);
	}	
	/**
	 * 上次触发预定约会时间
	 */
	public java.util.Date getLastTriggerReverseDatingTime() {return lastTriggerReverseDatingTime;}
	
	/**
	 * 上次触发预定约会时间
	 */
	public Dating setLastTriggerReverseDatingTime(java.util.Date lastTriggerReverseDatingTime) {this.lastTriggerReverseDatingTime = lastTriggerReverseDatingTime;return this;}
	
	/**
	 * 上次预定约会次数刷新时间
	 */
	public java.util.Date getLastReserveDatingRefreshTime() {return lastReserveDatingRefreshTime;}
	
	/**
	 * 上次预定约会次数刷新时间
	 */
	public Dating setLastReserveDatingRefreshTime(java.util.Date lastReserveDatingRefreshTime) {this.lastReserveDatingRefreshTime = lastReserveDatingRefreshTime;return this;}
	
	
	// 代理
	private org.game.db.proxy.bean.DatingProxy datingProxy = new org.game.db.proxy.bean.DatingProxy().build(this);
	
	public org.game.db.proxy.bean.DatingProxy getDatingProxy(){return datingProxy;}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.createDate;
        values[2] = this.modifiedDate;
        values[3] = this.playerId;
        values[4] = this.dialogueCount;
        values[5] = this.scriptIdList;
        values[6] = this.endNodeList;
        values[7] = this.lastTriggerReverseDatingTime;
        values[8] = this.lastReserveDatingRefreshTime;
        return values;
	}
	
	public Dating deepCopy(){
		Dating dating = null;
		try {
			dating = (Dating) super.clone();
		    dating.setCreateDate(ToolCopy.copyObject(this.createDate));
		    dating.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    dating.setDialogueCount(ToolCopy.copyObject(this.dialogueCount));
		    dating.setScriptIdList(ToolCopy.copyObject(this.scriptIdList));
		    dating.setEndNodeList(ToolCopy.copyObject(this.endNodeList));
		    dating.setLastTriggerReverseDatingTime(ToolCopy.copyObject(this.lastTriggerReverseDatingTime));
		    dating.setLastReserveDatingRefreshTime(ToolCopy.copyObject(this.lastReserveDatingRefreshTime));
		    // 克隆索引
		    dating.indexValues = ArrayUtils.clone(indexValues);
			return dating;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return dating;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.createDate);
        map.put(keys[2], this.modifiedDate);
        map.put(keys[3], this.playerId);
        map.put(keys[4], this.dialogueCount);
        map.put(keys[5], this.scriptIdList);
        map.put(keys[6], this.endNodeList);
        map.put(keys[7], this.lastTriggerReverseDatingTime);
        map.put(keys[8], this.lastReserveDatingRefreshTime);
        return map;
    }
    
    protected Dating createForMap(Object[] keys,Map map){
   		this.id = (long)map.get(keys[0]);
   		this.createDate = (java.util.Date)map.get(keys[1]);
   		this.modifiedDate = (java.util.Date)map.get(keys[2]);
   		this.playerId = (int)map.get(keys[3]);
   		this.dialogueCount = (Map)map.get(keys[4]);
   		this.scriptIdList = (List)map.get(keys[5]);
   		this.endNodeList = (List)map.get(keys[6]);
   		this.lastTriggerReverseDatingTime = (java.util.Date)map.get(keys[7]);
   		this.lastReserveDatingRefreshTime = (java.util.Date)map.get(keys[8]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.createDate);
        obj.put(keys[2], this.modifiedDate);
        obj.put(keys[3], this.playerId);
        obj.put(keys[4], toBytes(dialogueCount));
        obj.put(keys[5], toBytes(scriptIdList));
        obj.put(keys[6], toBytes(endNodeList));
        obj.put(keys[7], this.lastTriggerReverseDatingTime);
        obj.put(keys[8], this.lastReserveDatingRefreshTime);
        return obj;
    }
    
    protected Dating createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getLongValue(keys[0]);
	    this.createDate = obj.getDate(keys[1]);
	    this.modifiedDate = obj.getDate(keys[2]);
	    this.playerId = obj.getIntValue(keys[3]);
		this.dialogueCount = (Map)forBytesObject(obj.getBytes(keys[4]));
		this.scriptIdList = (List)forBytesObject(obj.getBytes(keys[5]));
		this.endNodeList = (List)forBytesObject(obj.getBytes(keys[6]));
	    this.lastTriggerReverseDatingTime = obj.getDate(keys[7]);
	    this.lastReserveDatingRefreshTime = obj.getDate(keys[8]);
        return this;
    }
    
    
    public Dating createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getLong(SOURCE_COLUMN_NAMES[0]);
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[1]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[2]);
	    this.playerId = rs.getInt(SOURCE_COLUMN_NAMES[3]);
		this.dialogueCount = (Map)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[4]));
		this.scriptIdList = (List)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[5]));
		this.endNodeList = (List)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[6]));
	    this.lastTriggerReverseDatingTime = rs.getTimestamp(SOURCE_COLUMN_NAMES[7]);
	    this.lastReserveDatingRefreshTime = rs.getTimestamp(SOURCE_COLUMN_NAMES[8]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeLong(this.id);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
	    byteBuf.writeInt(this.playerId);
	    byteBuf.writeObject(this.dialogueCount);
	    byteBuf.writeObject(this.scriptIdList);
	    byteBuf.writeObject(this.endNodeList);
	    byteBuf.writeDate(this.lastTriggerReverseDatingTime);
	    byteBuf.writeDate(this.lastReserveDatingRefreshTime);
    }
	
	protected Dating readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readLong(null);
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    this.playerId = byteBuf.readInt(null);
	    this.dialogueCount = (Map)byteBuf.readObject();
	    this.scriptIdList = (List)byteBuf.readObject();
	    this.endNodeList = (List)byteBuf.readObject();
	    this.lastTriggerReverseDatingTime = byteBuf.readDate(null);
	    this.lastReserveDatingRefreshTime = byteBuf.readDate(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		return true;
    }
    
	/** 取得[player]*/
	public Player getPlayerPkPlayerId(){
		return PlayerCache.me().getById(playerId);
	}
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public Dating insert(){
    	return DatingCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public Dating update(){
    	return DatingCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return DatingCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public Dating insertAndFlush(){
    	return DatingCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public Dating updateAndFlush(){
    	return DatingCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return DatingCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public Dating syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		indexValues[1] = SK_Plus.b(getPlayerId()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((long)key);
	}
//自定义内容起始位置



//自定义内容结束位置
}